package mt.client.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JOptionPane;
import javax.swing.JFrame;

import mt.comm.ClientComm;
/**
 * DisconnectListener disconnects the client from the server.
 * @author tom93d
 *
 */
public class DisconnectListener implements ActionListener, WindowListener{

	private ClientComm clientComm;
	private JFrame frame;
	
	/**
	 * This constructor receives the ClientComm and the Frame of the current MicroTrader client.
	 * @param clientComm
	 * @param frame
	 */
	public DisconnectListener(ClientComm clientComm, JFrame frame) {
		this.clientComm = clientComm;
		this.frame = frame;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		//Disconnect from the server
		clientComm.disconnect();
	//	System.out.println("Disconnected from server");
		JOptionPane.showMessageDialog(frame,"Disconnected");
	}

	@Override
	public void windowActivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosed(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosing(WindowEvent arg0) {
		//Disconnect form the server
		clientComm.disconnect();
	//	System.out.println("Disconnected from server");
		JOptionPane.showMessageDialog(frame,"Disconnected");
	}

	@Override
	public void windowDeactivated(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeiconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowIconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowOpened(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
